/*
 * 百度在线网络技术（北京）有限公司拥有本软件版权2022并保留所有权利。
 * Copyright 2022, Baidu.com,Inc 2:Baidu Online Network Technology (Beijing) Co.,Ltd,
 * All rights reserved.
 */

package com.azdebugit.suanfa.test.huawei;

public class MaxSameStr {
    public static String getMaxSameStr(String str1, String str2) {
        String maxString = (str1.length() > str2.length()) ? str1 : str2;
        String minString = (str1.length() < str2.length()) ? str1 : str2;
        String temp = "";

        for (int i = 0; i < minString.length(); i++) {
            for (int j = 0; j <= i; j++) {
                String str = minString.substring(j, minString.length() - i + j);
                if (maxString.contains(str)) {
                    if (temp.length() < str.length()) {
                        temp = str;
                    }
                }
            }
        }

        return temp;
    }

    public static void main(String[] args) {
        String str1 = "abcwherthel";
        String str2 = "cvhellobnm";

        System.out.println(getMaxSameStr(str1, str2));
    }
}